home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / System / VirusCheckerII / ARexx / VCtest.rexx < prev    next >
OS/2 REXX Batch file  |  1999-06-12  |  8KB  |  264 lines

  1. /* VCtest.rexx ===================================================
  2.  
  3.    This is a script which can be called from CLI, or from another
  4.    program or arexx script.
  5.  
  6.    Purpose: To make Virus_CheckerII test a single file, or files
  7.    -------  from a list.
  8.  
  9.    Usage: (a) From CLI (shell)
  10.    -----  ---------------------
  11.           rx VCtest <file path+name> OR  rx VCtest -L<list path+name>
  12.  
  13.           -L may be upper or lower case.
  14.           If a list is provided, this is a text file and it must carry
  15.             one file path+name on each line.
  16.           (If a path is not supplied, the current shell path is used.)
  17.  
  18.            (b) From DirOPus (Vn5 Magellan)
  19.            -------------------------------
  20.            (Button configuration)
  21.            
  22.            Function: AmigaDos  rx <path>VCtest.rexx> {f}
  23.                  or: Arexx     <path>VCtest.rexx> {f}
  24.  
  25.            Flags:    CD source
  26.                      Do all files
  27.                      No file quotes
  28.                      Output to window
  29.                      Recursive dirs
  30.                      Window close button
  31.                      Run asynchronously  (optional)
  32.  
  33.    Results:  VCtest will normally print to window one or more file
  34.    -------   names, each followed by one or more lines which  show
  35.              1. Number of viruses found.
  36.              2. Name of infected file (if virus found)
  37.              3. Name of virus found (if any)
  38.  
  39.              Lines 2 and 3 will be repeated if any further viruses found
  40.  
  41.              Output may be redirected to a text file.
  42.  
  43.              e.g. rx VCtest >hd0:tests/mytest -lBBS:uploads/testlist
  44.  
  45.    Notes:  Lha archives will be unpacked disregarding directories.
  46.    -----   This means that all files in the arcgive will be put into
  47.            the one work area (see config lines below). VC will not
  48.            need to unpack the files, and there is no danger of files
  49.            carrying a path (such as C:) which could cause them to
  50.            be put into places where they can do harm.
  51.  
  52.            The several unpackers referred to in the script should be
  53.            within your system's search paths, perhaps in C: or
  54.            Utilities. These are
  55.                Lha, Lzx, Pkax, Unarj, zoo, Unzip, DMS.
  56.  
  57.            If there are any which you don't intend to support,
  58.            then delete or disable lines in the script which refer
  59.            to these.
  60.  
  61.  
  62.  Author:
  63.  -------------------------------------------------------------------
  64.  John Marchant ('Gnome'). Bedford UK.           gnome@enterprise.net
  65.  Amiga 4000/40, A3000/30, A500                  Fidonet 2:257/137.16
  66.  Moonlight (Amiga) BBS. 6pm-8am (24hrs weekends)  +44 (0)1234 212752
  67.  Fax, Fido freq, Fido netmail accepted during open hours.
  68.  -------------------------------------------------------------------
  69.  (Above information correct at 28 October 1998)
  70.  
  71. =====================================================================*/
  72.  
  73. options results
  74. options failat 21
  75.  
  76. signal on failure
  77. signal on syntax
  78.  
  79. /* The following lines can be enabled, and will provide a
  80.    recorded 'trace' of the program.
  81. */
  82.  
  83. /*
  84. call open('STDERR','ram:tracefile','w')
  85. trace results
  86. */
  87.  
  88. /*=============== User configs ===================*/
  89.  
  90. WorkDir = 'T:Test'   /* Where you want archives to be unpacked for testing */
  91. VCdir  = 'Work1:utilities.1/Virus_Checker/'
  92.          /* Path to your virus checker, with trailing /   */
  93.  
  94. /*============ End of configs ================================*/
  95.  
  96. parse arg fpath junk
  97.  
  98. flist=''; infile=''; listinp=0
  99.  
  100. if left(fpath,2)='-l' | left(fpath,2)='-L' then do
  101.   flist=substr(fpath,3)     /* input file = list of paths+names */
  102.   listinp=1
  103. end
  104.  
  105. Home_Dir=Pragma('D')      /* determine current dir */ 
  106. call Pragma('S',64000)    /* set stack size  */
  107.  
  108. if exists(WorkDir) then
  109.   address command 'Delete >nil: 'workdir'/#? quiet' /* clear work area */
  110. else address command 'makedir 'WorkDir   /* else make work area */
  111.  
  112. call Load_VC
  113. if response>0 then do
  114.   say 'Can''t find '||VCdir||Virus_CheckerII
  115.   returncode=20
  116.   signal badexit
  117. end
  118.  
  119. if listinp then do
  120.   if open(chklist,flist,'r') =0 then do
  121.     say 'Cannot open '||flist
  122.     say
  123.     returncode=21
  124.     signal badexit
  125.   end
  126.  
  127.   do while ~eof(chklist)
  128.     fpath=readln(chklist)
  129.     if fpath='' then leave
  130.     if ~exists(fpath) then do
  131.       say 'Can''t find '||fpath
  132.       iterate
  133.     end
  134.     say 'Testing: '||fpath
  135.     call Unpack
  136.     if response=0 then call Viruscheck
  137.     say
  138.   end
  139.   call close(chklist)
  140. end
  141.  
  142. else do
  143.   if ~exists(fpath) then do
  144.     temp_path=Home_Dir||'/'||fpath
  145.     if exists(temp_path) then fpath=temp_path
  146.     else do
  147.       say 'Can''t find '||fpath
  148.       returncode=21
  149.       signal badexit
  150.     end
  151.   end
  152.   say 'Testing: '||fpath
  153.   call Unpack
  154.   if response=0 then call Viruscheck
  155.   say
  156. end
  157.  
  158. address command 'Delete >nil: 'workdir'/#? quiet'
  159. gnome=Pragma('D',Home_Dir)  /* return to original dir */
  160. exit
  161.  
  162. badexit:
  163.   gnome=Pragma('D',Home_Dir)
  164.   return returncode
  165.  
  166. /*--------------------------------------------------*/
  167.  
  168. Unpack:
  169. /* Checks to see if file is a recognized archive.
  170.    If so, unpacks it into work area.
  171.    If not, copies it into work area as is.
  172.    NOTE: .dms files are not unpacked, but are tested for integrity
  173. */
  174.  
  175.   response=0
  176.  
  177. /*
  178.   if index(fpath,'/')>0 then  /* allow for missing or invalid path */
  179.     fname=reverse(delstr(reverse(fpath),pos('/',reverse(fpath))))
  180.   else fname=fpath
  181. */
  182.  
  183.   if index(fpath,'/')=0 & index(fpath,':')=0 then do
  184.     fname=fpath
  185.     fpath=Home_Dir||'/'||fname
  186.   end
  187.  
  188.   If ~Open('file',fpath,'R') then Do
  189.     say 'Can''t open '||fpath
  190.     return 99
  191.   end
  192.  
  193.   fsig = readch('file',12)   /* read filetype signature */
  194.   call close('file')
  195.   if length(fsig) < 12 then do
  196.     say||fname' is too short to be genuine.'
  197.     return 99
  198.   end
  199.  
  200.   gnome=Pragma('D',WorkDir) /* set current dir to WorkArea */
  201.   select
  202.     when substr(fsig,3,3)='-lh' then Address Command 'LhA >NIL: -mMqa -P2 -x0 e '||fpath
  203.     when left(fsig,3)    = 'LZX'   then Address Command 'LZX >NIL: -m x '||fpath
  204.     when left(fsig,1)    = "1a"x   then Address Command 'Pkax >NIL: -e '||fpath
  205.     when left(fsig,2)    = "60ea"x then address command 'unarj >NIL: e '||fpath
  206.     when left(fsig,3)    = 'ZOO'   then Address Command 'Zoo >NIL: e// '||fpath 
  207.     when left(fsig,2)    = 'PK'    then Address Command 'unzip >NIL: '||fpath
  208.     when left(fsig,3) = "DMS" then do
  209.       say 'Can''t unpack a DMS file'
  210.       gnome=Pragma('D',Home_Dir) /* restore current dir */ 
  211.       address command 'dms >NIL: test '||fpath
  212.       say 'DMS integrity test returns error code '||RC
  213.       response=10
  214.       return response
  215.     end
  216.     otherwise do
  217.       gnome=Pragma('D',Home_Dir) /* restore current dir */ 
  218.       address command 'copy 'fpath' to 'WorkDir
  219.       return 0
  220.     end
  221.   end
  222.   response=RC  /* return code from unpackers */
  223.   if response ~=0 then say 'Unpacker returns error code '||response
  224.   gnome=Pragma('D',Home_Dir) /* restore current dir */ 
  225. return response
  226.   
  227. Viruscheck:
  228.   address 'Virus_CheckerII' 'SCAN '||WorkDir
  229.   vircount = VCHECK.0.0
  230.   if vircount = 'VCHECK.0.0' then vircount = +0 /* force numeric */
  231.   say '  '||vircount 'virus(es) found.'
  232.   if vircount ~=0 then do
  233.     do i=1 to vircount  /* was "to VCHECK.0.0"  */
  234.       say '    File: '||VCHECK.i.1||'  Virus: '||VCHECK.i.2
  235.     end
  236.     say
  237.   end
  238. return vircount
  239.  
  240. Load_VC:
  241.   response=0
  242.   if ~show(Ports,'Virus_CheckerII') then do
  243.     if exists(VCdir||'Virus_CheckerII') then do
  244.       address command 'run <>nil: '||VCdir||'Virus_CheckerII N XFD'
  245.       do i=1 to 3
  246.         address command 'waitforport Virus_CheckerII'
  247.         if RC=0 then break
  248.       end
  249.     end
  250.     if ~show(Ports,'Virus_CheckerII') then response=10
  251.   end
  252. return response
  253.  
  254.  
  255. /*------------------------------------------------------------*/
  256. SYNTAX:
  257. FAILURE:
  258.    Error = rc
  259.    Myline = SIGL
  260.    gnome=Pragma('D',Home_Dir)
  261.    say 'Error: '||Error||' Line '||myline||'. '||ErrorText(Error)
  262. Exit 30
  263.  
  264.